// pages/activity/pay/submitOrder/submitOrder.js

const app = getApp()
var http = require("../../../../utils/httpUtils")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderId: '',
    discountsType: false,
    region: ['陕西省', '西安市', '雁塔区'],
    sexs: [{
        value: '0',
        name: '男'
      },
      {
        value: '1',
        name: '女'
      },
    ]
  },

  getData: function () {
    var that = this
    // 获取数据
    var urls = app.globalData.SERVER_IP + '/order/confirm_order/o_id/' + that.data.orderId
    http.G(urls, {}, (res) => {
      console.log("获取信息", res.result)
      that.setData({
        dataInfo: res.result
      })
    }, (err) => {
      console.log("获取信息失败")
      console.log(err)
    })

  },
  submitBtn: function (e) {
    console.log("点击了确认支付按钮！")
    var that = this
    var urls = app.globalData.WX_SERVER + "/app/wx/microAppPayOrder?userId=" + wx.getStorageSync('userInfo').userid + "&orderId=" + this.data.orderId
    // 查询登录信息
    console.log(wx.getStorageSync('userInfo'))

    // 下单
    http.P(urls, {}, (res) => {
      console.log(res.data)

      wx.requestPayment({
        timeStamp: res.data.timeStamp,
        nonceStr: res.data.nonceStr,
        package: res.data.package,
        signType: 'MD5',
        paySign: res.data.paySign,
        success(res) {
          wx.reLaunch({
            url: '../paySuccess/paySuccess?money=' + that.data.dataInfo.orderData[0].o_pay_money + '&o_activity_type=' + that.data.dataInfo.orderData[0].o_activity_type + '&o_type=' + that.data.dataInfo.orderData[0].o_type + '&ono=' + that.data.dataInfo.orderData[0].o_no + '&o_id=' + that.data.dataInfo.orderData[0].o_oid,
          })
        },
        fail(res) {}
      })
    }, (err) => {
      console.log("获取信息失败")
      console.log(err)
    })

  },

  my_coupon: function (options) {
    wx.navigateTo({
      url: '../../../user_center/my_coupon/my_coupon'
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    this.setData({
      // orderId: 6889
      orderId: options.ono
    })

    this.getData()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.hideShareMenu({})
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})